home *** CD-ROM | disk | FTP | other *** search
/ c't freeware shareware 1997 / CT_SW_97.ISO / pc / software / entwickl / macos / ingwdef.hqx / IngisWDEF 1.2 ƒ / IngisWDEFUtils.p < prev    next >
Text File  |  1996-08-18  |  9KB  |  328 lines

  1. { *** Unility unit for the "IngisWDEF" WDEF building package *** }
  2.  
  3. {© 1994-1995 by Ingemar Ragnemalm}
  4. {You may use it freely as long as credits are given in the final program.}
  5.  
  6.  
  7. unit IngisWDEFUtils;
  8.  
  9. interface
  10. {$IFC UNDEFINED THINK_PASCAL}
  11.     uses Types, QuickDraw, ToolUtils, OSUtils;
  12. {$ENDC}
  13.  
  14.  
  15. {Color save and restore}
  16.     function HasCQDraw: Boolean;
  17.     procedure SaveColors (var saveForeColor, saveBackColor: RGBColor);
  18.     procedure RestoreColors (saveForeColor, saveBackColor: RGBColor);
  19.     procedure DefaultColors;
  20. {Standard colors. For perfect results, you should check out Technote TB33, but I didn't have}
  21. {THAT much energy.}
  22.     function BoxFillColor: RGBColor;
  23.     function BoxFrameColor: RGBColor;
  24.     function BoxShadowColor: RGBColor;
  25.     function SurroundColor: RGBColor;
  26.     function DraglineColor: RGBColor;
  27. {Standard drawings, to conform with standard windows}
  28.     procedure DrawStdCloseHit (rclose: Rect);
  29.     procedure StdFrameBox (closeBox: Rect; colorFlag: Boolean);
  30.     procedure StdCloseBox (closeBox: Rect; colorFlag: Boolean);
  31.     procedure StdZoomBox (closeBox: Rect; colorFlag: Boolean);
  32.     procedure StdDragIcon (where: Point; colorFlag: Boolean);
  33.  
  34. implementation
  35.  
  36. {*****************************************************************************}
  37. {Some color stuff, for saving and restoring the foreground and background colors}
  38. {Called only when we run in color!}
  39.  
  40.     function HasCQDraw: Boolean;
  41.         var
  42.             theWorld: SysEnvRec;
  43.     begin
  44.         HasCQDraw := false;
  45.         if SysEnvirons(1, theWorld) = noErr then
  46.             HasCQDraw := theWorld.hasColorQD;
  47.     end;
  48.  
  49.     procedure SaveColors (var saveForeColor, saveBackColor: RGBColor);
  50.     begin
  51.         if not HasCQDraw then
  52.             exit(SaveColors);
  53.         GetForeColor(saveForeColor);
  54.         GetBackColor(saveBackColor);
  55.         DefaultColors;
  56.     end;
  57.  
  58.     procedure RestoreColors (saveForeColor, saveBackColor: RGBColor);
  59.     begin
  60.         if not HasCQDraw then
  61.             exit(RestoreColors);
  62.         RGBForeColor(saveForeColor);
  63.         RGBBackColor(saveBackColor);
  64.     end;
  65.  
  66.     procedure DefaultColors;
  67.         var
  68.             tmpCol: RGBColor;
  69.     begin
  70.         if not HasCQDraw then
  71.             exit(DefaultColors);
  72. {Foreground black}
  73.         tmpCol.red := 0;
  74.         tmpCol.green := 0;
  75.         tmpCol.blue := 0;
  76.         RGBForeColor(tmpCol);
  77. {Background white}
  78.         tmpCol.red := -1;
  79.         tmpCol.green := -1;
  80.         tmpCol.blue := -1;
  81.         RGBBackColor(tmpCol);
  82.     end;
  83.  
  84. {Standard bluish colors.}
  85.     function BoxFillColor: RGBColor;
  86.     begin
  87.         BoxFillColor.red := 43690;
  88.         BoxFillColor.green := 43690;
  89.         BoxFillColor.blue := 43690;
  90.     end;
  91.     function BoxFrameColor: RGBColor;
  92.     begin
  93.         BoxFrameColor.red := 52428;
  94.         BoxFrameColor.green := 52428;
  95.         BoxFrameColor.blue := 65535; {=-1=$ffff}
  96.     end;
  97.     function BoxShadowColor: RGBColor;
  98.     begin
  99.         BoxShadowColor.red := 13107;
  100.         BoxShadowColor.green := 13107;
  101.         BoxShadowColor.blue := 26214;
  102.     end;
  103.     function SurroundColor: RGBColor;
  104.     begin
  105.         SurroundColor.red := 61166;
  106.         SurroundColor.green := 61166;
  107.         SurroundColor.blue := 61166;
  108.     end;
  109.     function DraglineColor: RGBColor;
  110.     begin
  111.         DraglineColor.red := 30583;
  112.         DraglineColor.green := 30583;
  113.         DraglineColor.blue := 30583;
  114.     end;
  115. {--------}
  116.  
  117. {Draws the standard "hit" icon. Looks best in the standard size.}
  118. {Set colors before calling it, if color is desired (i.e. possible)}
  119.     procedure DrawStdCloseHit (rclose: Rect);
  120.     begin
  121.         EraseRect(rclose);
  122.         FrameRect(rclose);
  123.         MoveTo(rclose.left + 2, rclose.top + 2);
  124.         LineTo(rclose.right - 3, rclose.bottom - 3);
  125.         MoveTo(rclose.left + 2, rclose.bottom - 3);
  126.         LineTo(rclose.right - 3, rclose.top + 2);
  127.         MoveTo(rclose.left + 1, (rclose.top + rclose.bottom) div 2);
  128.         Line(rclose.right - rclose.left - 2, 0);
  129.         MoveTo((rclose.right + rclose.left) div 2, rclose.top + 1);
  130.         Line(0, rclose.bottom - rclose.top - 2);
  131.         InsetRect(rclose, 4, 4);
  132.         EraseRect(rclose);
  133.     end;
  134.  
  135.     procedure StdFrameBox (closeBox: Rect; colorFlag: Boolean);
  136.     begin
  137.         if colorFlag then
  138.             begin
  139. {$IFC UNDEFINED THINK_PASCAL}
  140.                 RGBForeColor(BoxShadowColor());
  141.                 RGBBackColor(BoxFillColor());
  142. {$ELSEC}
  143.                 RGBForeColor(BoxShadowColor);
  144.                 RGBBackColor(BoxFillColor);
  145. {$ENDC}
  146.                 EraseRect(closeBox);
  147.                 FrameRect(closeBox);
  148.                 OffsetRect(closeBox, 1, 1);
  149. {$IFC UNDEFINED THINK_PASCAL}
  150.                 RGBForeColor(BoxFrameColor());
  151. {$ELSEC}
  152.                 RGBForeColor(BoxFrameColor);
  153. {$ENDC}
  154.                 FrameRect(closeBox);
  155.             end
  156.         else
  157.             begin
  158.                 FrameRect(closeBox);
  159.                 InsetRect(closeBox, 1, 1);
  160.                 EraseRect(closeBox);
  161.             end;
  162.     end;
  163.  
  164.     procedure StdCloseBox (closeBox: Rect; colorFlag: Boolean);
  165.     begin
  166.         if colorFlag then
  167.             begin
  168.                 InsetRect(closeBox, -1, -1);    { Make an empty frame around it    }
  169. {$IFC UNDEFINED THINK_PASCAL}
  170.                 RGBForeColor(SurroundColor());
  171. {$ELSEC}
  172.                 RGBForeColor(SurroundColor);
  173. {$ENDC}
  174.                 FrameRect(closeBox);
  175.                 InsetRect(closeBox, 1, 1);
  176.  
  177.                 closeBox.right := closeBox.right - 1;
  178.                 closeBox.bottom := closeBox.bottom - 1;
  179.  
  180. {$IFC UNDEFINED THINK_PASCAL}
  181.                 RGBForeColor(BoxShadowColor());
  182.                 RGBBackColor(BoxFillColor());
  183. {$ELSEC}
  184.                 RGBForeColor(BoxShadowColor);
  185.                 RGBBackColor(BoxFillColor);
  186. {$ENDC}
  187.                 EraseRect(closeBox);
  188.                 MoveTo(closeBox.left, closeBox.bottom);
  189.                 LineTo(closeBox.left, closeBox.top);
  190.                 LineTo(closeBox.right, closeBox.top);
  191.                 MoveTo(closeBox.left + 2, closeBox.bottom - 1);
  192.                 LineTo(closeBox.right - 1, closeBox.bottom - 1);
  193.                 LineTo(closeBox.right - 1, closeBox.top + 2);
  194.  
  195.                 OffsetRect(closeBox, 1, 1);
  196. {$IFC UNDEFINED THINK_PASCAL}
  197.                 RGBForeColor(BoxFrameColor());
  198. {$ELSEC}
  199.                 RGBForeColor(BoxFrameColor);
  200. {$ENDC}
  201.                 FrameRect(closeBox);
  202.             end
  203.         else
  204.             begin
  205.                 InsetRect(closeBox, -1, -1);    { Blast a hole in the drag bar        }
  206.                 EraseRect(closeBox);            {   pattern                        }
  207.                 InsetRect(closeBox, 1, 1);
  208.                 FrameRect(closeBox);            { Now draw the close box            }
  209.             end;
  210.     end;
  211.  
  212.     procedure StdZoomBox (closeBox: Rect; colorFlag: Boolean);
  213.     begin
  214.         if colorFlag then
  215.             begin
  216.                 InsetRect(closeBox, -1, -1);    { Make an empty frame around it    }
  217. {$IFC UNDEFINED THINK_PASCAL}
  218.                 RGBForeColor(SurroundColor());
  219. {$ELSEC}
  220.                 RGBForeColor(SurroundColor);
  221. {$ENDC}
  222.                 FrameRect(closeBox);
  223.                 InsetRect(closeBox, 1, 1);
  224.  
  225.                 closeBox.right := closeBox.right - 1;
  226.                 closeBox.bottom := closeBox.bottom - 1;
  227.  
  228. {$IFC UNDEFINED THINK_PASCAL}
  229.                 RGBForeColor(BoxShadowColor());
  230.                 RGBBackColor(BoxFillColor());
  231. {$ELSEC}
  232.                 RGBForeColor(BoxShadowColor);
  233.                 RGBBackColor(BoxFillColor);
  234. {$ENDC}
  235.                 EraseRect(closeBox);
  236.                 MoveTo(closeBox.left, closeBox.bottom);
  237.                 LineTo(closeBox.left, closeBox.top);
  238.                 LineTo(closeBox.right, closeBox.top);
  239.                 MoveTo(closeBox.left + 2, closeBox.bottom - 1);
  240.                 LineTo(closeBox.right - 1, closeBox.bottom - 1);
  241.                 LineTo(closeBox.right - 1, closeBox.top + 2);
  242.  
  243.                 MoveTo(closeBox.left + 2, closeBox.bottom - 1 - 3);
  244.                 LineTo(closeBox.right - 1 - 3, closeBox.bottom - 1 - 3);
  245.                 LineTo(closeBox.right - 1 - 3, closeBox.top + 2);
  246.  
  247.                 OffsetRect(closeBox, 1, 1);
  248. {$IFC UNDEFINED THINK_PASCAL}
  249.                 RGBForeColor(BoxFrameColor());
  250. {$ELSEC}
  251.                 RGBForeColor(BoxFrameColor);
  252. {$ENDC}
  253.                 FrameRect(closeBox);
  254.             end
  255.         else
  256.             begin
  257.                 InsetRect(closeBox, -1, -1);    { Blast a hole in the drag bar        }
  258.                 EraseRect(closeBox);            {   pattern                        }
  259.                 InsetRect(closeBox, 1, 1);
  260.                 FrameRect(closeBox);            { Now draw the close box            }
  261.                 MoveTo(closeBox.left + 1, closeBox.bottom - 1 - 4);
  262.                 LineTo(closeBox.right - 1 - 4, closeBox.bottom - 1 - 4);
  263.                 LineTo(closeBox.right - 1 - 4, closeBox.top + 1);
  264.             end;
  265.     end;
  266.  
  267.     procedure StdDragIcon (where: Point; colorFlag: Boolean);
  268.         var
  269.             tmpRect, smallRect, largeRect: Rect;
  270.  
  271.         procedure FrameBox (box: Rect);
  272.         begin
  273.             FrameRect(box);
  274.             InsetRect(box, 1, 1);
  275.             EraseRect(box);
  276.         end;
  277.  
  278.     begin
  279.         if colorFlag then
  280.             begin
  281.                 SetRect(smallRect, where.h + 2, where.v + 2, where.h + 8, where.v + 8);
  282.                 SetRect(largeRect, smallRect.left + 1, smallRect.top + 1, smallRect.right + 4, smallRect.bottom + 4);
  283.  
  284. {Draw the two boxes on top of each other}
  285.  
  286. {$IFC UNDEFINED THINK_PASCAL}
  287.                 RGBBackColor(BoxFillColor());
  288.                 RGBForeColor(BoxShadowColor());
  289.                 FrameBox(largeRect);
  290.                 OffsetRect(largeRect, 1, 1);
  291.                 RGBForeColor(BoxFrameColor());
  292.  
  293.                 FrameRect(largeRect);
  294.  
  295.                 RGBBackColor(BoxFillColor());
  296.                 RGBForeColor(BoxShadowColor());
  297.                 FrameBox(smallRect);
  298.                 OffsetRect(smallRect, 1, 1);
  299.                 RGBForeColor(BoxFrameColor());
  300. {$ELSEC}
  301.                 RGBBackColor(BoxFillColor);
  302.                 RGBForeColor(BoxShadowColor);
  303.                 FrameBox(largeRect);
  304.                 OffsetRect(largeRect, 1, 1);
  305.                 RGBForeColor(BoxFrameColor);
  306.  
  307.                 FrameRect(largeRect);
  308.  
  309.                 RGBBackColor(BoxFillColor);
  310.                 RGBForeColor(BoxShadowColor);
  311.                 FrameBox(smallRect);
  312.                 OffsetRect(smallRect, 1, 1);
  313.                 RGBForeColor(BoxFrameColor);
  314. {$ENDC}
  315.                 FrameRect(smallRect);
  316.             end
  317.         else
  318.             begin
  319.                 SetRect(smallRect, where.h + 2, where.v + 2, where.h + 9, where.v + 9);
  320.                 SetRect(largeRect, smallRect.left + 2, smallRect.top + 2, smallRect.right + 4, smallRect.bottom + 4);
  321.  
  322.                 FrameBox(largeRect);
  323.                 FrameBox(smallRect);
  324.             end;
  325.  
  326.     end;
  327.  
  328. end.